package com.buka.communicate.activity;

import android.os.Bundle;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.buka.communicate.R;
import com.buka.communicate.adapter.FamilyDetailAdapter;
import com.facebook.drawee.view.SimpleDraweeView;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import net.neiquan.applibrary.base.BaseActivity;
import net.neiquan.applibrary.wight.CommonPopupWindow;
import net.neiquan.applibrary.wight.RefreshLayout;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/11/15 0015.
 */

public class FamilyDetailActivity extends BaseActivity implements RefreshLayout.RetryListener, XRecyclerView.LoadingListener {

    @InjectView(R.id.recyclerview)
    XRecyclerView mRecyclerview;
    @InjectView(R.id.refesh_ly)
    RefreshLayout mRefeshLy;
    @InjectView(R.id.exitFamily)
    LinearLayout exitFamily;
    @InjectView(R.id.inviteFamily)
    LinearLayout inviteFamily;
    @InjectView(R.id.recruitBroadCast)
    LinearLayout recruitBroadCast;
    @InjectView(R.id.bottomLL)
    LinearLayout bottomLL;
    private LinearLayout focusLL;
    private TextView infoEdit;
    private LinearLayout familyManage;
    private LinearLayout callFamilyMember;
    private LinearLayout manageFamilyMember;
    private FamilyDetailAdapter adapter;

    @Override
    public int getRootViewId() {
        return R.layout.activity_family_detail;
    }

    @Override
    public void setViews() {
        setHeadViews();
        setAdapter();
    }

    @Override
    public void initData() {

    }


    @Override
    public void onRetryClick() {

    }


    @Override
    public void onRefresh() {

    }

    @Override
    public void onLoadMore() {

    }

    @OnClick({R.id.exitFamily, R.id.inviteFamily, R.id.recruitBroadCast})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.exitFamily:
                break;
            case R.id.inviteFamily:
                break;
            case R.id.recruitBroadCast:
                break;
        }
    }

    protected void setHeadViews() {
        setTitleTv("家族详情");
        View headView = LayoutInflater.from(this).inflate(R.layout.layout_family_head, null);
        focusLL = (LinearLayout) headView.findViewById(R.id.focusLL);
        infoEdit = (TextView) headView.findViewById(R.id.infoEdit);
        familyManage = (LinearLayout) headView.findViewById(R.id.familyManage);
        callFamilyMember = (LinearLayout) headView.findViewById(R.id.callFamilyMember);
        manageFamilyMember = (LinearLayout) headView.findViewById(R.id.manageFamilyMember);
        mRecyclerview.addHeaderView(headView);
        ((SimpleDraweeView) headView.findViewById(R.id.mHeadImg)).setImageURI("http://img2.imgtn.bdimg.com/it/u=266057472,3867980612&fm=27&gp=0.jpg");
        callFamilyMember.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showCallPopWindow();
            }
        });
        manageFamilyMember.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
    }

    private void setAdapter() {
        adapter = new FamilyDetailAdapter(this, null);
        mRecyclerview.setAdapter(adapter);
        StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(1,
                StaggeredGridLayoutManager.VERTICAL);
        layoutManager.setOrientation(StaggeredGridLayoutManager.VERTICAL);
        mRecyclerview.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
        mRecyclerview.setLoadingMoreProgressStyle(ProgressStyle.BallRotate);
//        mRecyclerview.setArrowImageView(R.mipmap.iconfont_downgrey);
        mRecyclerview.setHasFixedSize(true);
        mRecyclerview.setLayoutManager(layoutManager);
        mRefeshLy.setRetryListener(this);

        mRecyclerview.setLoadingListener(this);
        mRecyclerview.setLoadingMoreEnabled(false);
        mRecyclerview.setPullRefreshEnabled(true);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.inject(this);
    }


    private void showCallPopWindow() {
        CommonPopupWindow popupWindow = new CommonPopupWindow.Builder(this)
                //设置PopupWindow布局
                .setView(R.layout.call_member_pop)
                //设置宽高
                .setWidthAndHeight(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT)
                //设置动画
                .setAnimationStyle(R.style.Animation_Fade)
                //设置背景颜色，取值范围0.0f-1.0f 值越小越暗 1.0f为透明
                .setBackGroundLevel(0.5f)
                //设置PopupWindow里的子View及点击事件
                .setViewOnclickListener(new CommonPopupWindow.ViewInterface() {
                    @Override
                    public void getChildView(final PopupWindow popupWindow, View view, int layoutResId) {
                        SimpleDraweeView mHeadImg = (SimpleDraweeView) view.findViewById(R.id.mHeadImg);
                        mHeadImg.setImageURI("http://img2.imgtn.bdimg.com/it/u=266057472,3867980612&fm=27&gp=0.jpg");
                        TextView mCancelTv = (TextView) view.findViewById(R.id.mCancelTv);
                        TextView mSureTv = (TextView) view.findViewById(R.id.mSureTv);
                        mCancelTv.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                popupWindow.dismiss();
                            }
                        });
                        mSureTv.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                popupWindow.dismiss();
                            }
                        });
                    }
                })
                //设置外部是否可点击 默认是true
                .setOutsideTouchable(true)
                //开始构建
                .create();
        //弹出PopupWindow
        popupWindow.showAtLocation(mRecyclerview, Gravity.CENTER, 0, 0);
    }
}
